package database

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
)

//连接数据库所需要的相信息
const (
	username = "root"
	password = "LLTL520"
	address  = "127.0.0.1" //地址
	port     = "3306"      //端口号
	Dbname   = "csms"
)
var DB *sql.DB
//init 创建数据库，链接
func init() {
	var err error
	//打开sql
	DB, err = sql.Open("mysql", username+":"+password+"@tcp("+address+":"+port+")/"+Dbname+"?charset=utf8")
	if err != nil {
		panic(err)
	}
	err = DB.Ping()
	if err != nil {
		panic(err)
	}
}
//Close 关闭数据库
func Close() {
	DB.Close()
}
